<template>
	<view class="content">
		<view class="uni-panel-c">
			<view class="uni-panel-bottom">
				<view class="uni-panel-item">
					<!-- <image class="uni-image" src="/static/img/back.png" mode="widthFix" @click="clickBack"></image> -->
					<view class="uni-panel-left">
						<text class="uni-text-item">你好，{{accountName}}老师，请选择要测试的学生</text>
					</view>
				</view>
				<view class="uni-panel">
					<view class="uni-panel-book" v-for="(item, index) in listBook" :key="index" @click="clickBtnItem(item)">
						<image class="uni-word-image" src="/static/img/student.png" mode="widthFix" ></image>
						<view class="uni-panel-book-right">
							<text class="uni-text-word" >{{item.nickname}}</text>
							<text class="uni-text-word" v-if='item.username'>{{'('+ item.username+')'}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
			 
	</view>
</template>

<script>
	import { getUserList } from '@/api/api.js';
	import store from "../../store";
	import { HTTP_REQUEST_URL } from '@/config/app.js';
	export default {
		mounted() {
		        // #ifdef APP-PLUS
		        plus.screen.lockOrientation('landscape');
		        // #endif
		    },
		data() {
			return {
				userId: 0,
				accountName: '',
				apiUrl: HTTP_REQUEST_URL,
				listBook: [],
				isEveryday: false,
			}
		},
		onLoad(options) {
			this.isEveryday = options.isEveryday=='true';
			const userInfo = store.state.app.userInfo;
			if( userInfo){
				this.accountName = userInfo.nickname;
				this.userId = userInfo.id;
			}
			this.getStudentList();
		},
		methods: {
			getStudentList(){
				this.listBook = [{nickname:this.accountName, username:'自己复习', id:this.userId}];
				let params = {pageSize:999, params: {master_id:this.userId}};
				getUserList(params).then(res => {
					if(0 == res.code){
						for( let item of res.data.rows){
							this.listBook.push(item);
						}
					}else{
						uni.showToast({
						    title: res.msg,
							icon: 'none',
						    duration: 2000
						});
					}
				})
			},
			clickBack(){
				uni.navigateBack();
			},
			clickBtnItem(item){
				if( item.status == 1){
					uni.showToast({
					    title: "用户还未激活，请联系管理员开通！",
						icon: 'none',
					    duration: 2000
					});
					return;
				}
				if( item.id != this.userId){
					// 选择学生账号
					uni.setStorageSync('student_info', item);
				}else{
					uni.removeStorageSync('student_info');
				}
				uni.redirectTo({ 
					url : '/pages/home/index'
				});
			},
		}
	}
</script>

<style>
	page {
		height: 100%;
	}
	.content {
		width: 100%;
		height: 100%;
		background-image: url('../../static/img/bg.jpg');
		background-size: 100% 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.uni-panel-c {
		width: 90%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}
	
	.uni-panel-top {
		width: 100%;
		height: 20%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}
	.uni-image {
		width: 6%;
	}
	.uni-text-logo{
		color: black;
		font-size: 10vmin;
		margin-left: 2%;
		text-align: center;
		font-weight: bold;
		letter-spacing: 10rpx;
		font-family: "楷体";
	}
	
	.uni-panel-bottom-bk {
		position: absolute;
		left: 5%;
		top: 20%;
		width: 90%;
		height: 80%;
		background-color: white;
		opacity: 0.3;
		border-radius: 40rpx;
	}
	.uni-panel-bottom {
		margin-top: 8%;
		width: 100%;
		height: 80%;
		display: flex;
		flex-direction: column;
		align-items: center;
		z-index: 1;
	}
	.uni-panel-item {
		width: 96%;
		height: 15%;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.uni-panel-left {
		display: flex;
		flex-direction: column;
		margin-left: 2%;
	}
	
	.uni-text-item{
		font-size: 5vmin;
		color: white;
		font-weight: bold;
		letter-spacing: 1rpx;
		text-shadow:
		    -1px -1px 0 #000,
		    1px -1px 0 #000,
		    -1px 1px 0 #000,
		    1px 1px 0 #000; /* 调整偏移量和颜色来设置描边宽度和颜色 */
	}
	
	.uni-panel {
		width:100%;
		height: 85%;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		overflow: auto;
	}
	
	.uni-panel-book {
		height: 25%;
		width: 22%;
		margin-left: 3%;
		margin-top: 20rpx;
		background-color: #c8ede5;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-radius: 10rpx;
	}
	
	.uni-word-image {
		margin-left: 1%;
		width: 30%;
		height: 70%;
	}
	
	.uni-panel-book-right{
		display: flex;
		flex-direction: column;
	}
	
	.uni-text-word{
		white-space: nowrap;
		font-size: 4vmin;
		color: black;
		margin-left: 1%;
	}
	
</style>
